package com.ljz.service.serviceImple;

import com.ljz.dao.EmpDao;
import com.ljz.dao.daoImpl.EmpDaoImpl;
import com.ljz.entity.Emp;
import com.ljz.service.EmpService;
import com.ljz.untils.DBUtils3;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

public class EmpleServiceImple implements EmpService {
    private EmpDao empDao = new EmpDaoImpl();
    public List<Emp> findAll() {
        List<Emp> all = empDao.findAll();
        return all;
    }

    @Override
    public int insert(Emp emp) {
        Connection conn = DBUtils3.getConn();
        try {
            conn.setAutoCommit(false);
            int num = empDao.add(emp);
            conn.commit();
            return num;
        } catch (SQLException e) {
            e.printStackTrace();
            try {
                conn.rollback();
                return 0;
            } catch (SQLException ex) {
                ex.printStackTrace();
            }
        }finally {
            try {
                conn.close();
            } catch (SQLException e) {
                throw new RuntimeException(e);
            }
        }
        return 0;
    }
}
